package Tools;

import jade.core.AID;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

public class OpinionBase implements Serializable{
	private HashMap<AID,HashMap<String,InternalRepresentation>> opinions;
	
	public OpinionBase(){
		opinions= new HashMap<AID,HashMap<String,InternalRepresentation>>();
		
	}
	//Puts all opinions of one agent
	public void putOpinions(AID aid,HashMap<String,InternalRepresentation> agentsOpinions){
		opinions.put(aid, agentsOpinions);
	}
	//Put a single opinion of one agent
	public void put(AID aid,String obj,InternalRepresentation agentsOpinion){
		if(!opinions.containsKey(aid))
			opinions.put(aid, new HashMap<String,InternalRepresentation>());
		opinions.get(aid).put(obj, agentsOpinion);
	}
	//Gets all opinions of one agent
	public HashMap<String,InternalRepresentation> getOpinions(AID aid){
		return opinions.get(aid);
	}
	//Gets single opinion of one agent
	public InternalRepresentation getAgentOpinion(AID aid,String obj){
		return opinions.get(aid).get(obj);
		
	}
	//Gets summary opinion about one object
	public ArrayList<PolarRepresentation> getObjectOpinions(String obj){
		ArrayList<PolarRepresentation> result=new ArrayList<PolarRepresentation>();
		for(AID key:opinions.keySet()){
			if(opinions.get(key).get(obj)!=null){
				result.add((PolarRepresentation)(opinions.get(key).get(obj)));

			}
		}
		return result;
	}
	
	
}
